package edu.cs.usask.ca.silver.plugin.rcp.handlers.create;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.handlers.HandlerUtil;

import edu.cs.usask.ca.silver.plugin.rcp.dialogs.create.CreateGroupDialog;
import edu.cs.usask.ca.silver.plugin.rcp.handlers.create.helper.CreateDataProcedures;
import edu.cs.usask.ca.silver.plugin.rcp.views.projectviewer.ProjectViewI;

public class CreateGroupHandler extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {

		ProjectViewI view = (ProjectViewI) HandlerUtil
				.getActiveWorkbenchWindow(event).getActivePage()
				.findView(event.getParameter("projectviewid"));

		CreateGroupDialog dialog = new CreateGroupDialog(HandlerUtil
				.getActiveWorkbenchWindow(event).getShell());

		dialog.create();

		if (dialog.open() == Window.OK) {
			CreateDataProcedures.createNewGroupFromCreateGroupDialog(dialog,
					view.getAssociatedStorage(), view.getAssociatedUserID());
			view.refresh();
		}

		return null;
	}
}
